wizard: display error message when ToS haven't been accepted yet
authorJyrki Gadinger <nilsding@nilsding.org>
Wed, 12 Feb 2025 11:33:20 +0000 (12:33 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 20 Feb 2025 10:35:56 +0000 (10:35 +0000)
Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
src/gui/connectionvalidator.cpp
src/gui/owncloudsetupwizard.cpp
src/gui/tray/syncstatussummary.cpp
src/libsync/owncloudpropagator_p.h

index ebe1c1af525f6f0b6ee8e6d180cb372350fab23c..31467ec3f4bf0306839a8fed2563f58b98267803 100644 (file)
@@ -221,13 +221,20 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply)
         stat = CredentialsWrong;
 
     } else if (reply->error() != QNetworkReply::NoError) {
-        _errors << job->errorStringParsingBody();
+        QByteArray body;
+        _errors << job->errorStringParsingBody(&body);
 
         const int httpStatus =
             reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
         if (httpStatus == 503) {
             _errors.clear();
             stat = ServiceUnavailable;
+        } else if (httpStatus == 403) {
+            const auto davException = job->errorStringParsingBodyException(body);
+            if (davException == QStringLiteral(R"(OCA\TermsOfService\TermsNotSignedException)")) {
+                qCInfo(lcConnectionValidator) << "The terms of service need to be signed";
+                stat = NeedToSignTermsOfService;
+            }
         }
     }
 
index ae11ff72ae83b41dc794350a8bf2aa92a5822939..66282a067a2937ab92647521472ab8060a29dfdc 100644 (file)
@@ -31,6 +31,7 @@
 #include "networkjobs.h"
 #include "owncloudgui.h"
 #include "owncloudsetupwizard.h"
+#include "owncloudpropagator_p.h"
 #include "sslerrordialog.h"
 #include "wizard/owncloudwizard.h"
 #include "wizard/owncloudwizardcommon.h"
@@ -421,10 +422,17 @@ void OwncloudSetupWizard::slotAuthError()
 
         // Provide messages for other errors, such as invalid credentials.
     } else if (reply->error() != QNetworkReply::NoError) {
+        auto davException = OCC::getExceptionFromReply(reply);
+
         if (!_ocWizard->account()->credentials()->stillValid(reply)) {
             errorMsg = tr("Access forbidden by server. To verify that you have proper access, "
                           "<a href=\"%1\">click here</a> to access the service with your browser.")
                            .arg(Utility::escape(_ocWizard->account()->url().toString()));
+        } else if (!davException.first.isEmpty() && davException.first == QStringLiteral(R"(OCA\TermsOfService\TermsNotSignedException)")) {
+            qCInfo(lcWizard) << "Terms of service not accepted yet!";
+            // TODO: it would be cool to display a new wizard page containing the terms of service
+            errorMsg = tr("Please accept the <a href=\"%1\">Terms of Service</a> with your browser and try again.")
+                           .arg(Utility::escape(_ocWizard->account()->url().toString()));
         } else {
             errorMsg = job->errorStringParsingBody();
         }
index cd31daac96677c2553691ee99cba6cf541fff14a..0e5d43c921a0115171b1d28614ab215a77200398 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "syncstatussummary.h"
 #include "accountfwd.h"
+#include "accountstate.h"
 #include "folderman.h"
 #include "navigationpanehelper.h"
 #include "networkjobs.h"
index beb150648db87591a6c0a535f09fcc96c8c66c49..95e383493ce67a6aaa4834612876445b6a66c467 100644 (file)
@@ -69,8 +69,8 @@ inline QPair<QByteArray, QByteArray> getExceptionFromReply(QNetworkReply * const
         return {};
     }
     const auto httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
-    // only for BadRequest and UnsupportedMediaType
-    if (httpStatusCode != 400 && httpStatusCode != 415) {
+    // only for BadRequest, Forbidden, and UnsupportedMediaType
+    if (!(httpStatusCode == 400 || httpStatusCode == 403 || httpStatusCode == 415)) {
         return {};
     }